//
//  ST_ChatUserHeader.swift
//  btvideo
//
//  Created by mac on 2020/5/15.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import NIMSDK
import SwifterSwift
import SwiftyJSON
import SwiftyAttributes
import SwiftyUserDefaults
/**
 收到别人消息提示
 */
class ST_ChatUserHeader: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(avatar_image_view)
        avatar_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(110)
            make.top.equalToSuperview().offset(30)
            make.centerX.equalToSuperview()
        }
        
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.height.equalTo(20)
            make.top.equalTo(avatar_image_view.snp.bottom).offset(10)
        }
        
        self.addSubview(tips_label)
        tips_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.height.equalTo(22)
            make.top.equalTo(titleLabel.snp.bottom).offset(15)
        }
        
        
        self.addSubview(tips_content_label)
        tips_content_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(tips_label.snp.bottom).offset(10)
        }
        
        
        self.addSubview(collectionView)
        collectionView.snp.makeConstraints { (make) in
            make.right.left.equalToSuperview()
            make.height.equalTo(95)
            make.top.equalTo(tips_content_label.snp.bottom).offset(15)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK: - Properties
    fileprivate lazy var avatar_image_view:UIImageView = {
     let control = UIImageView()
        control.contentMode = .scaleAspectFill
        control.cornerRadius = 110/2.0
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(push_user_center))
        
        control.addGestureRecognizer(tap)
        
        control.isUserInteractionEnabled = true
        
      return control
  }()
    
    
    var push_user_center_closure:(()->())?
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#8290A5")
//        control.numberOfLines = 0
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var detect_before_str = "未进行真人头像认证"
    
    fileprivate lazy var detected_str = "已通过真人头像认证"
    
    fileprivate lazy var detect_before_content_str:NSAttributedString = {
        
        let attrStr = NSMutableAttributedString.init(string: "对方未进行真人认证，如出现违规情况，可以进行屏\n蔽、拉黑、举报处理")
        
        attrStr.addAttributes(tips_content_attr, range: NSRange.init(location: 0, length: attrStr.length))
        
        return attrStr
    }()
    
    fileprivate lazy var detected_content_str:NSAttributedString = {
        
        let attrStr = NSMutableAttributedString.init(string:  "对方已通过真人头像认证，聊天过程中请提高警惕\n不要轻易给自己的其他社交账号")
        
        attrStr.addAttributes(tips_content_attr, range: NSRange.init(location: 0, length: attrStr.length))
        
        return attrStr
    }()
    
    
    fileprivate lazy var price_content_str:NSAttributedString = {
        
        
        let attrStr =  NSMutableAttributedString.init(string: "为表诚意和防止骚扰，对方和你聊天需要支付")
        
        attrStr.addAttributes(tips_content_attr, range: NSRange.init(location: 0, length: attrStr.length))
        
        let attrStr0 =  NSMutableAttributedString.init(string: "\(self.myRequireCoin)甜心币/条")
        attrStr0.addAttributes(tips_yellow_content_attr, range: NSRange.init(location: 0, length: attrStr0.length))
        
        
        let attrStr1 =  NSMutableAttributedString.init(string: "消息，回复对方之后，")
        attrStr1.addAttributes(tips_content_attr, range: NSRange.init(location: 0, length: attrStr1.length))
        
        let attrStr2 =  NSMutableAttributedString.init(string: "\(self.myRequireCoin.float/10.0)元")
        attrStr2.addAttributes(tips_yellow_content_attr, range: NSRange.init(location: 0, length: attrStr2.length))
        
        
        let attrStr3 =  NSMutableAttributedString.init(string: "等值\(Defaults[.PandaStr])将自动赠送到你的\(Defaults[.PandaLinkStr])，互相喜欢配对成功后聊天\(Defaults[.PandaWriteKindStr])")
        attrStr3.addAttributes(tips_content_attr, range: NSRange.init(location: 0, length: attrStr3.length))
        
        
        attrStr.append(attrStr0)
        attrStr.append(attrStr1)
        attrStr.append(attrStr2)
        attrStr.append(attrStr3)
        
        return attrStr
    }()
    
    
    fileprivate lazy var tips_label:UILabel = {
        let control = UILabel.init()
        control.textColor = Color.init(hexString: "#333333")
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var tips_content_attr:[NSAttributedString.Key : Any] = {
        
        let p = NSParagraphStyle.create_line_spacing_paragraph_style(lineSpacing: 3)
        
        p.alignment = .center
        
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor(red: 0.67, green: 0.71, blue: 0.75, alpha: 1),.paragraphStyle:p]
        
        return attr
    }()
    
    fileprivate lazy var tips_yellow_content_attr:[NSAttributedString.Key : Any] = {
        
        let p = NSParagraphStyle.create_line_spacing_paragraph_style(lineSpacing: 3)
        
        p.alignment = .center
        
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor.init(hex: 0xFEC207)!,.paragraphStyle:p]
        
        return attr
    }()
    
    
    fileprivate lazy var tips_content_label:UILabel = {
        let control = UILabel.init()
        control.numberOfLines = 0
        control.textAlignment = .center
        return control
    }()
    
    
    fileprivate lazy var layout:UICollectionViewFlowLayout = {
        let controlLayout = UICollectionViewFlowLayout()
        controlLayout.scrollDirection = .horizontal
        controlLayout.minimumLineSpacing = 5
        controlLayout.minimumInteritemSpacing = 0
        controlLayout.itemSize = CGSize.init(width: 95, height: 95)
        controlLayout.sectionInset = UIEdgeInsets.init(top: 0, left: 15, bottom: 0, right: 15)
        return controlLayout
    }()
    
    fileprivate lazy var collectionView:UICollectionView = {
        let control = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: self.layout)
        control.backgroundColor = Color.white
        control.delegate = self
        control.dataSource = self
        
        control.register(cellWithClass: ST_ChatUserST_PeculiarityCell.self)
        
        if #available(iOS 11.0, *) {
            control.contentInsetAdjustmentBehavior = .never
        }
        control.alwaysBounceHorizontal = true
        control.showsVerticalScrollIndicator = false
        control.showsHorizontalScrollIndicator = false
        return control
    }()
    
    
    
//    MARK: -Bind Model
    fileprivate var avatarUrl = ""
    fileprivate var nickName = ""
    var age:Int?
    var location:String?
    var face_status = 0
    var myRequireCoin = 0
    
    
    var ownArray = [ST_ChatUserST_PeculiarityCellModel](){
        didSet{
            
            self.collectionView.isHidden = ownArray.count < 1
            
            self.previewArray = ownArray.map { (item) -> ST_MWPhoto in
                
                guard let url = item.content.big_remote_image().url , let media = ST_MWPhoto.init(url: url) else{
                    return ST_MWPhoto()
                }
                
                return media
            }
            
            
            self.collectionView.reloadData()
        }
    }
    
    
    fileprivate var previewArray = [ST_MWPhoto]()
    
    var sessionId = ""{
        didSet{
            
    //                优先显示后台返回的头像 昵称
            if let info = BINP.fetch_nickname_with_avatar(userId: sessionId){
                avatarUrl = info.avatar
                nickName = info.userName
            }else{
    //                再查询网易云的头像
                if let nimUser = NIMSDK.shared().userManager.userInfo(sessionId),let minUserInfo = nimUser.userInfo {
                    if let aUrl = minUserInfo.avatarUrl{
                        avatarUrl = aUrl.ni_m_url()
                    }
                    nickName = minUserInfo.nickName ?? ""
                }else{
                    print("网易云获取用户信息失败 analysis(message） !!! ---",sessionId)
                }
            }
            
            self.bind_model()
        }
    }
    
    
    fileprivate func bind_model(){
        
        avatar_image_view.sd_setImage(with: avatarUrl.url, completed: nil)
        
        var contentStr = nickName
        
        if let str = self.age,str > 17{
            contentStr += "·" + str.string + "岁"
        }
        
        if let str = self.location,str.count > 0{
            contentStr += "·" + str
        }
        
        titleLabel.text = contentStr
        
        if self.face_status != 3{
            tips_label.text = self.detect_before_str
            tips_content_label.attributedText = self.detect_before_content_str
        }else{
            tips_label.text = self.detected_str
            tips_content_label.attributedText = self.detected_content_str
        }
        
        if self.myRequireCoin > 0 && ST_BTUserInfoManager.shared.current_account_info?.userinfo?.sex == .female{
            tips_content_label.attributedText = self.price_content_str
        }
        
    }
    
    
    
    func bind(age:Int,address:String,face_status:Int,myRequireCoin:Int){
        
        self.age = age
        
        self.location = address
        
        self.face_status = face_status
        
        self.myRequireCoin = myRequireCoin
        
        bind_model()
    }

}


extension ST_ChatUserHeader:UICollectionViewDelegate,UICollectionViewDataSource{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return ownArray.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withClass: ST_ChatUserST_PeculiarityCell.self, for: indexPath)
        
        cell.model = ownArray[safe:indexPath.row]
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        
        guard let browser = ST_MWPhotoBrowser.init(photos: self.previewArray) else{
            return
        }
        
        browser.displayActionButton = false
        
        browser.setCurrentPhotoIndex(indexPath.row.uInt)
        
        let nav = UINavigationController.init(rootViewController: browser)
        
        GlobalPresent(toController: nav)
    }
    
        
    @objc func push_user_center(){
        
        push_user_center_closure?()
        
    }
    
}

//MARK: -
class ST_ChatUserST_PeculiarityCell: UICollectionViewCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        
        contentView.addSubview(content_label_root_view)
        content_label_root_view.snp.makeConstraints { (make) in
            make.top.left.equalToSuperview().offset(5)
            make.height.equalTo(20)
        }
        
        content_label_root_view.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 0, left: 6, bottom: 0, right: 6))
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    fileprivate lazy var cover_image_view:UIImageView = {
         let control = UIImageView()
          control.contentMode = .scaleAspectFill
        control.cornerRadius = 10
          return control
      }()
        
    fileprivate lazy var content_label_root_view:UIView = {
         let control = UIView()
      control.backgroundColor = .white
      control.cornerRadius = 10
          return control
      }()
        
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = UIColor(hexString: "#333333")
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 10, weight: UIFont.Weight.medium)
        return control
    }()
    
    var model:ST_ChatUserST_PeculiarityCellModel?{
        didSet{
            guard let m = model else{return}
            
            content_label.text = m.featureName
            
            cover_image_view.pin_setImage(from: m.content.compress_small_image(width: 95*3).url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        }
    }
    
}


//MARK: - Cell Model

class ST_ChatUserST_PeculiarityCellModel : NSObject{

    var content : String!
    var featureName : String!

    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON){
        content = json["content"].stringValue
        featureName = json["feature_name"].stringValue
        super.init()
    }
}



/**
 自己 真人认证提示
 */
class ST_ChatFaceTipsHeader: UIView {
    
    static let height = (10 + 20 + 40).cgFloat
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(contentBtn)
        contentBtn.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 0, left: 0, bottom: 30, right: 0))
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var contentBtn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        let font = UIFont.systemFont(ofSize: 14)
        
        let attrString = NSMutableAttributedString(string: "完成真人认证，真实的自己更能获得聊天和进一步了解！")
        
        let attr: [NSAttributedString.Key : Any] = [.font: font,.foregroundColor: UIColor(red: 0.67, green: 0.71, blue: 0.75, alpha: 1)]
        
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))

        let strSubAttr2: [NSMutableAttributedString.Key: Any] = [.font: font,.foregroundColor: UIColor(red: 1, green: 0.76, blue: 0.03,alpha:1.000000)]
        
        attrString.addAttributes(strSubAttr2, range: NSRange(location: 2, length: 6))

        control.setAttributedTitle(attrString, for: UIControl.State.normal)
        
        control.addTarget(self, action: #selector(detect_click), for: UIControl.Event.touchUpInside)
        
        return control
    }()

    
    @objc func detect_click(){
        
        if FACE_AVATAE_STATE == 2{
          
            let failure = ST_MatchFaceFailureController()
            
            failure.overCurrentContext = true
            
            GlobalPresent(toController: failure)
            
            return
            
        }
        
        if [0,1].contains(FACE_AVATAE_STATE){
            DetectFaceHandle()
        }
    }

}




//MARK: - Model

struct ST_ChatTitleViewModel {
    var nickname:String
    var isVip:Bool
    var isGoddess:Bool
    var isNoble:Bool
    /// 友谊的图标标识
    var icon:String?
}

extension ST_ChatTitleViewModel{
    
    func textColor() -> UIColor? {
        
        if isNoble{
            return UIColor.init(hex: 0xFB5D5D)
        }else if isVip{
            return UIColor.init(hex: 0xFEC207)
        }else{
            return UIColor.init(hex: 0x333333)
        }
    }
}

class ST_ChatTitleView:UIView{
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    fileprivate lazy var vip_image_view:UIImageView = {
        let control = UIImageView.init(image: SC.YYMemberSignImage)
        return control
   }()
    
    fileprivate lazy var goddess_image_view:UIImageView = {
        let control = UIImageView.init(image: SC.YYGoddessSignImage)
        return control
   }()
    
    
     fileprivate lazy var ship_image_view:UIImageView = {
          let control = UIImageView()
           control.contentMode = .scaleAspectFill
           return control
       }()
    
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.semibold)
        return control
    }()
    
    
    func refresh_ship_sign(url:String){
        
        self.model?.icon = url
        
        self.layout_from_model()
    }
    
    
    func update_user_title(str:String){
        
        titleLabel.text = str
    }
    
    var model:ST_ChatTitleViewModel?{
        didSet{
            self.layout_from_model()
        }
    }
    
    
    fileprivate func layout_from_model(){
        
        self.removeSubviews()
        
        guard let m = model else { return  }
        
        titleLabel.text = m.nickname
        
        titleLabel.textColor = m.textColor()
        
        if let url = m.icon{
            
            ship_image_view.sd_setImage(with: url.url, completed: nil)
            
            self.addSubview(ship_image_view)
            ship_image_view.snp.makeConstraints { (make) in
                make.centerY.right.equalToSuperview()
                make.width.height.equalTo(16)
            }
            if m.isGoddess{
                
                self.addSubview(goddess_image_view)
                goddess_image_view.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview().offset(-5)
                    make.height.equalTo(30)
                    make.width.equalTo(35)
                    make.right.equalTo(ship_image_view.snp.left).offset(-5)
                }
                
                self.addSubview(titleLabel)
                titleLabel.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview()
                    make.right.equalTo(goddess_image_view.snp.left).offset(-5)
                    make.left.equalToSuperview().offset(35)
                }
                
            }else if m.isVip{
                
                self.addSubview(vip_image_view)
                vip_image_view.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview()
                    make.width.height.equalTo(16)
                    make.right.equalTo(ship_image_view.snp.left).offset(-5)
                }
                
                self.addSubview(titleLabel)
                titleLabel.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview()
                    make.right.equalTo(vip_image_view.snp.left).offset(-5)
                    make.left.equalToSuperview()
                }
                
                
            }else{
                
                
                self.addSubview(titleLabel)
                titleLabel.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview()
                    make.right.equalTo(ship_image_view.snp.left).offset(-5)
                    make.left.equalToSuperview()
                }
            }
        }else{
            
            if m.isGoddess{
                
                self.addSubview(goddess_image_view)
                goddess_image_view.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview().offset(-5)
                    make.height.equalTo(30)
                    make.width.equalTo(35)
                    make.right.equalToSuperview().offset(-5)
                }
                
                self.addSubview(titleLabel)
                titleLabel.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview()
                    make.right.equalTo(goddess_image_view.snp.left).offset(-5)
                    make.left.equalToSuperview().offset(35)
                }
                
                
                
            }else if m.isVip{
                
                
                self.addSubview(vip_image_view)
                vip_image_view.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview()
                    make.width.height.equalTo(16)
                    make.right.equalToSuperview().offset(-5)
                }
                
                self.addSubview(titleLabel)
                titleLabel.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview()
                    make.right.equalTo(vip_image_view.snp.left).offset(-5)
                    make.left.equalToSuperview()
                }
                
                
            }else{
                
                
                self.addSubview(titleLabel)
                titleLabel.snp.makeConstraints { (make) in
                    make.centerY.equalToSuperview()
                    make.right.equalToSuperview().offset(-5)
                    make.left.equalToSuperview()
                }
            }
            
        }
        
        
    }
    
}



class ChatTipsForMeView: UIView {
    
    var figured_height = 0.cgFloat
    
    
    static func display_tips_for_me()->Bool{
        
        if  ownPeculiarityCount < 1 ||  FACE_AVATAE_STATE != 3  {
            return true
        }
//        女的没有设置微信号
        else if ST_BTUserInfoManager.shared.current_account_info?.userinfo?.sex == .female &&  ST_BTUserInfoManager.shared.additional_attributes?.wechatNumber == nil{
            return true
        }else{
            return false
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        var firstView:UIView?
        
        if ownPeculiarityCount < 1{
            
            let h1 = pec_tips_view.set(title: "添加3个及以上【我的特质】，对方回复你的几率至少会\n增加2倍哦！", btnText: "点击添加特质") {
                
                push_to_push_peculiarity_controller(navigationController: self.parentViewController?.navigationController)
                
            }
            
            self.addSubview(pec_tips_view)
            pec_tips_view.snp.makeConstraints { (make) in
                
                if let top_view = firstView {
                make.top.equalTo(top_view.snp.bottom).offset(10)
                }else{
                make.top.equalToSuperview().offset(10)
                }
                make.left.equalToSuperview().offset(15)
                make.right.equalToSuperview().offset(-15)
                make.height.equalTo(h1)
            }
            self.figured_height = 10 + h1
            firstView = pec_tips_view
        }
        
        if FACE_AVATAE_STATE != 3{
            
            let h0 = face_tips_view.set(title: "完成真人认证，真实的自己更能获得聊天和进一步了解！", btnText: "点击真人认证") {
                
                if FACE_AVATAE_STATE == 2{
                  
                    let failure = ST_MatchFaceFailureController()
                    
                    failure.overCurrentContext = true
                    
                    GlobalPresent(toController: failure)
                    
                    return
                    
                }
                
                if FACE_AVATAE_STATE == 1{
                    DetectFaceHandle()
                }else if FACE_AVATAE_STATE == 4{
                    
                    let vc = ST_BTHUDController.init(noticeText: "你的头像还在审核中")
                    
                    GlobalPresent(toController: vc, animated: false)
                    
                    main_thread_execute(afterDelay: 2.5) {
                        vc.dismiss(animated: false, completion: nil)
                    }
                }
                
            }
            
            self.addSubview(face_tips_view)
            face_tips_view.snp.makeConstraints { (make) in
                
                if let top_view = firstView {
                make.top.equalTo(top_view.snp.bottom).offset(10)
                }else{
                make.top.equalToSuperview().offset(10)
                }
                
                make.left.equalToSuperview().offset(15)
                make.right.equalToSuperview().offset(-15)
                make.height.equalTo(h0)
            }
            
            firstView = face_tips_view
            
            self.figured_height += 10 + h0
        }
        
//        女的 没有微信
        if  ST_BTUserInfoManager.shared.current_account_info?.userinfo?.sex == .female &&  ST_BTUserInfoManager.shared.additional_attributes?.wechatNumber == nil {
            
            let json = SCComponets.rich_text_storage_component.json["kk_chat_header"]
            
            let h0 = set_intimacy_tips_view.set(title: json[0]["title"].stringValue, btnText: json[0]["text"].stringValue) {
                
                GlobalPresent(toController: ST_BitianValueController())
                
            }
            
            self.addSubview(set_intimacy_tips_view)
            set_intimacy_tips_view.snp.makeConstraints { (make) in
                if let top_view = firstView {
                make.top.equalTo(top_view.snp.bottom).offset(10)
                }else{
                make.top.equalToSuperview().offset(10)
                }
                make.left.equalToSuperview().offset(15)
                make.right.equalToSuperview().offset(-15)
                make.height.equalTo(h0)
            }
            self.figured_height += 10 + h0
            firstView = set_intimacy_tips_view
            
            
            let h1 = wechat_tips_view.set(title: json[1]["title"].stringValue, btnText: json[1]["text"].stringValue) {
                
                GlobalPresent(toController: ST_BitianValueController())
                
            }
            
            self.addSubview(wechat_tips_view)
            wechat_tips_view.snp.makeConstraints { (make) in
                if let top_view = firstView {
                make.top.equalTo(top_view.snp.bottom).offset(10)
                }else{
                make.top.equalToSuperview().offset(10)
                }
                make.left.equalToSuperview().offset(15)
                make.right.equalToSuperview().offset(-15)
                make.height.equalTo(h1)
            }
            self.figured_height += 10 + h1
            firstView = wechat_tips_view
        }
        
        
        self.figured_height += 10
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var pec_tips_view:ST_PrivateChatHeaderTipsChildView = {
       
        let control = ST_PrivateChatHeaderTipsChildView()
        
        return control
    }()
    
    fileprivate lazy var face_tips_view:ST_PrivateChatHeaderTipsChildView = {
       
        let control = ST_PrivateChatHeaderTipsChildView()
        
        return control
    }()
    
    fileprivate lazy var set_intimacy_tips_view:ST_PrivateChatHeaderTipsChildView = {
       
        let control = ST_PrivateChatHeaderTipsChildView()
        
        return control
    }()
    
    fileprivate lazy var wechat_tips_view:ST_PrivateChatHeaderTipsChildView = {
       
        let control = ST_PrivateChatHeaderTipsChildView()
        
        return control
    }()
}

//MARK: - Child View
class ST_PrivateChatHeaderTipsChildView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.init(hex: 0xF5F8FA)
        self.cornerRadius = 15
        
        
        self.addSubview(label)
        label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalToSuperview().offset(-33)
        }

        self.addSubview(btn)
        btn.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.height.equalTo(44)
            make.bottom.equalToSuperview()
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    fileprivate lazy var label:UILabel = {
       
        let control = UILabel()
        
        control.numberOfLines = 0
        
        return control
    }()
    
    fileprivate lazy var btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)
        
        control.setTitleColorForAllStates(UIColor.init(hex: 0xFEC207)!)
        
        control.addTarget(self, action: #selector(click_handle), for: UIControl.Event.touchUpInside)
        
        return control
    }()
    
    fileprivate lazy var attr: [NSAttributedString.Key : Any] = {
        
        return [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 1),.paragraphStyle:NSParagraphStyle.create_line_spacing_paragraph_style(lineSpacing: 2)]
        
    }()
    
    
    func set(title:String,btnText:String,btnClick:@escaping (()->()))->CGFloat{
        
        btn.setTitleForAllStates(btnText)
        
        let str = NSMutableAttributedString(string: title)
        
        str.addAttributes(self.attr, range: NSRange(location: 0, length: str.length))
        
        label.attributedText = str
        
        self.click_closure = btnClick
        
        return str.height(withConstrainedWidth: ScreenWidth - 50) + 10 + 33
        
    }
    
    
    var click_closure:(()->())?
    @objc fileprivate func click_handle(){
        click_closure?()
    }
    
}

